import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:hzy_normal_widget/hzy_normal_widget.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:hzy_template/config/dataconfig/language_info_config.dart';
import '../../../config/config_index.dart';
import '../../../config/models/tf_config_model.dart';

/// 创建登录按钮
Widget configLoginBtn(String text, Function ontap) {
  return InkWell(
    onTap: () {
      ontap();
    },
    child: Container(
      padding: const EdgeInsets.only(
        top: 10,
        bottom: 10,
      ),
      decoration: BoxDecoration(
        color: HzyColorConfig().colthemes,
        borderRadius: BorderRadius.all(
          Radius.circular(
            6.r,
          ),
        ),
      ),
      width: 160,
      alignment: Alignment.center,
      child: Text(
        text,
        style: TextStyleMacor.fontMedium(16.sp, HzyColorConfig().colonlywhite),
      ),
    ),
  );
}

Widget configQuickRegistration({
  required BuildContext context,
  required Function ontap,
}) {
  return InkWell(
    onTap: () {
      ontap();
    },
    child: Container(
      padding: EdgeInsets.only(
        top: 10.w,
        bottom: 10.w,
      ),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.all(
          Radius.circular(
            6.r,
          ),
        ),
      ),
      width: 160.w,
      alignment: Alignment.center,
      child: Text(
        configLanguageMessage(LanguageConfig.oneclikclogin),
        style: FontConfig().fontMedium14LightGrey,
      ),
    ),
  );
}

/// 创建用户协议
Widget createuserargeementWidget(bool isselct, Function ontap,
    {bool isshowregist = false}) {
  IconData icon = Icons.radio_button_unchecked;
  Color iconColor = HzyColorConfig().colplacetextcolor;
  if (isselct) {
    icon = Icons.radio_button_checked;
    iconColor = HzyColorConfig().colthemes;
  }
  return Expanded(
    child: Container(
      alignment: Alignment.bottomCenter,
      padding: EdgeInsets.only(bottom: 20.w),
      child: Row(
        children: [
          InkWell(
            onTap: () {
              ontap();
            },
            child: Container(
              padding: EdgeInsets.all(5.w),
              child: Icon(
                icon,
                size: 16.w,
                color: iconColor,
              ),
            ),
          ),
          Expanded(
            child: RichText(
              text: TextSpan(
                children: [
                  TextSpan(
                    text: configLanguageMessage(LanguageConfig.acceptbeginmsg),
                    style: FontConfig().fontMedium12PlaceColor,
                  ),
                  TextSpan(
                    text: "《" +
                        configLanguageMessage(LanguageConfig.serviceagreement) +
                        "》",
                    style: FontConfig().fontMedium14Theme,
                    recognizer: TapGestureRecognizer()
                      ..onTap = () {
                        currentToPage(PageIdConfig.webviewpag,
                            arguments: "http://jiexinshengwu.com/Fyhxy.html");
                      },
                  ),
                  TextSpan(
                    text: configLanguageMessage(LanguageConfig.andstr),
                    style: FontConfig().fontMedium12PlaceColor,
                  ),
                  TextSpan(
                    text: "《" +
                        configLanguageMessage(LanguageConfig.privacypolicy) +
                        "》",
                    style: FontConfig().fontMedium14Theme,
                    recognizer: TapGestureRecognizer()
                      ..onTap = () {
                        currentToPage(PageIdConfig.webviewpag,
                            arguments: "http://jiexinshengwu.com/Fyszc.html");
                      },
                  ),
                  TextSpan(
                    text: isshowregist
                        ? configLanguageMessage(
                            LanguageConfig.informationcollect)
                        : "",
                    style: FontConfig().fontMedium12PlaceColor,
                  ),
                ],
              ),
            ),
          )
        ],
      ),
    ),
  );
}

/// 创建失败msg 显示框
Widget createerrormsgWidget(String msg) {
  return Container(
    padding: EdgeInsets.all(10.w),
    alignment: Alignment.centerLeft,
    child: Text(
      msg,
      style: TextStyleMacor.fontMedium(
        14.sp,
        CommentColorS.cole41335,
      ),
    ),
  );
}

/// 创建输入框
Widget createNormalTextField(
  BuildContext context,
  TfConfigModel model, {
  bool isvisibility = true,
  Function? ontap,
  Function(String)? onchange,
  double? titleW,
}) {
  return Container(
    padding: const EdgeInsets.only(
      left: 10,
      right: 10,
    ),
    child: Row(
      children: [
        SizedBox(
          width: titleW,
          child: Text(
            model.label!,
            style: FontConfig().fontMedium14Black,
          ),
        ),
        Gaps.hGap15,
        Expanded(
          child: TextField(
            obscureText: model.obscureText && !isvisibility,
            cursorColor: HzyColorConfig().colthemes,
            decoration: InputDecoration(
              border: InputBorder.none,
              contentPadding: const EdgeInsets.fromLTRB(
                0,
                0,
                0,
                0,
              ),
              hintText: model.hintText,
              hintStyle: FontConfig().fontMedium14PlaceColor,
            ),
            onChanged: (value) {
              if (onchange != null) {
                onchange(value);
              }
              model.text = value;
            },
            onEditingComplete: () {
              CommentTools.keydissmiss(context);
            },
          ),
        ),
        model.obscureText && model.text != null && model.text!.isNotEmpty
            ? InkWell(
                onTap: () {
                  if (ontap != null) {
                    ontap();
                  }
                },
                child: SizedBox(
                  width: 32.w,
                  height: 32.w,
                  child: Icon(
                    isvisibility ? Icons.visibility : Icons.visibility_off,
                    size: 16.w,
                  ),
                ),
              )
            : Container()
      ],
    ),
  );
}
